<template>
	<div>
		<el-dialog :title="$t('action.add')" width="70%" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_short_name')" prop="short_name">
							<el-input v-model="form.short_name" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_short_name')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_name')" prop="name">
							<el-input v-model="form.name" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_name')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				<el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_multiple')" prop="multiple">
							<draggable v-model="form.multiple" v-bind="{group:'item'}" handle=".multiple-handle">
							<el-row v-for="(item,i) in form.multiple" :key="i">
								<el-col :span="9">
							    <el-form-item class="activeItem">
									<el-input  v-model="item.times" placeholder="倍数"/>
								</el-form-item>
								</el-col>
								<el-col :span="9">
							    <el-form-item class="activeItem">
									<el-input style="position:relative;left:5px;" v-model="item.rate" placeholder="管理费%"/>
								</el-form-item>
								</el-col>
								<el-col :span="4">
									<el-button type="danger" size="mini" style="position:relative;left:15px"  icon="el-icon-close" @click="deleteItem('multiple',i)"></el-button>
									<el-button class="multiple-handle" type="success" size="mini" style="position:relative;left:15px" icon="el-icon-rank"></el-button>
								</el-col>
							</el-row>
							</draggable>
							<div>
								<el-button type="info" icon="el-icon-plus" style="padding:5px 7px" size="mini" @click="addItem('multiple')">{{$t('action.add')}}</el-button>
								<el-button v-if="form.multiple.length > 0" type="warning" icon="el-icon-delete" style="padding:5px 7px" size="mini" @click="clearItem('multiple')">{{$t('action.clear')}}</el-button>
							</div>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_number_min')" prop="number_min">
							<el-input v-model="form.number_min" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_number_min')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_number_max')" prop="number_max">
							<el-input v-model="form.number_max" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_number_max')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_time_min')" prop="time_min">
							<el-input v-model="form.time_min" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_time_min')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_time_max')" prop="time_max">
							<el-input v-model="form.time_max" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_time_max')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_warning')" prop="warning">
							<el-input v-model="form.warning" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_warning')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_close')" prop="close">
							<el-input v-model="form.close" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_close')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_times')" prop="times">
							<el-input v-model="form.times" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_times')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_limit_delay')" prop="limit_delay">
							<el-input v-model="form.limit_delay" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_limit_delay')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_profit')" prop="profit">
							<el-input v-model="form.profit" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_profit')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.CapitalType_status')" prop="status">
                            <el-select style="width:100%" v-model="form.status" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="开启" :value="1"></el-option>
                                <el-option key="1"  label="关闭" :value="0"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_fee')" prop="fee">
							<el-input v-model="form.fee" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_fee')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_explain1')" prop="explain1">
							<el-input  type="textarea" autoComplete="off" v-model="form.explain1"  :autosize="{ minRows: 2, maxRows: 4}" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_explain1')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.CapitalType_explain2')" prop="explain2">
							<el-input  type="textarea" autoComplete="off" v-model="form.explain2"  :autosize="{ minRows: 2, maxRows: 4}" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.CapitalType_explain2')})"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
				</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">{{$t('system.confirm')}}</span>
					<span v-else>{{$t('system.submitting')}}</span>
				</el-button>
				<el-button :size="size" @click="closeForm">{{$t('system.cancel')}}</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { add } from '@/api/app/capitaltype'
import draggable from "vuedraggable"



export default {
	name:'capitalTypeadd',
	components: {
	   		draggable,
	   	   
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		querys:{
			type:Object,
		},
	},
	data(){
		return {
		    dialog:{
			},
			
			form: {
			   short_name:'',
			   name:'',
			   multiple:[],
			   number_min:'',
			   number_max:'',
			   time_min:'',
			   time_max:'',
			   warning:'',
			   close:'',
			   times:'',
			   limit_delay:'',
			   profit:'',
			   status:1,
			   create_time:'',
			   fee:'',
			   explain1:'',
			   explain2:'',
			},
		    initial:{},   
			loading:false,
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
			}
		}
	},
	methods: {
		open(){
		  if(this.querys){
		  }
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					add(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: this.$t('system.success'), type: 'success'})
							this.$emit('refresh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		addItem(key){
			this.form[key].push({})
		},
		deleteItem(key,index){
			this.form[key].splice(index,1)
		},
		clearItem(key){
			this.form[key] = []
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
